//
//  HRTopicListCell.m
//  Hear
//
//  Created by mac on 2017/11/27.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HRTopicListCell.h"
#import "HRDynamicCell.h"
#import "HRCoverTimeModel.h"

@interface HRTopicListCell ()
@property (nonatomic, strong)UIView *backView;
@property(nonatomic, strong)UILabel *titleLabel;
@property(nonatomic, strong)HRSoundButton *soundButton;
@property(nonatomic, strong)UILabel *timeLabel;
@property(nonatomic, strong)UILabel *statusLabel;
@property(nonatomic, strong)UIButton *ageinButton;
@property(nonatomic, strong)UIButton *deleteButotn;

@end
@implementation HRTopicListCell
-(void)setLayout:(HRTopicListLayout *)layout{
    _layout = layout;
    HRFunChatModel *chatModel = layout.chatModel;
    
    [self setupSubFrame];
    self.titleLabel.text = chatModel.TopicTitle;
    
    self.timeLabel.text = [HRCoverTimeModel covetActiveTime:chatModel.CreateTime];
    
    if ([chatModel.Status intValue] ==1){//发布中
        self.statusLabel.text = @"发布中";
        self.statusLabel.textColor = CustomColor(255, 142, 142, 1);
    }else{
        self.statusLabel.text = @"已结束";
        self.statusLabel.textColor = SecondTextColor;
    }
    
    self.soundButton.funChatModel = chatModel;
    self.ageinButton.hidden = NO;

    if (![chatModel.IsUse intValue]){
        self.statusLabel.text = @"话题违规";
        self.statusLabel.textColor = CustomColor(255, 142, 142, 1);
        self.ageinButton.hidden = YES;
    }
}
- (void)setupSubFrame{

WeakSelf
    dispatch_async(dispatch_get_main_queue(), ^{
        weakSelf.backView.frame = _layout.backViewRect;
        weakSelf.backView.layer.shadowColor = [UIColor blackColor].CGColor;
        weakSelf.backView.layer.shadowRadius      = 3;
        weakSelf.backView.layer.shadowOpacity     = 0.2;
        weakSelf.backView.layer.shadowOffset      = CGSizeMake(1, 1);
        weakSelf.backView.layer.shadowPath        = [UIBezierPath bezierPathWithRect:weakSelf.backView.bounds].CGPath;
        
        weakSelf.titleLabel.frame = _layout.titleLabelRect;
        
        weakSelf.soundButton.frame = _layout.soundButtonRect;
        
        weakSelf.timeLabel.frame = _layout.timeLabelRect;
        
        weakSelf.statusLabel.frame = _layout.statusLabelRect;
        
        weakSelf.deleteButotn.frame = _layout.deleteButotnRect;
        
        weakSelf.ageinButton.frame = _layout.ageinButtonRect;
    });
    
    
    
    
}

+(instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *cellID = @"HRTopicListCell";
    
    HRTopicListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if(!cell){
        cell = [[HRTopicListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.backgroundColor = [UIColor whiteColor];
        self.backView = [[UIView alloc] init];
        [self.contentView addSubview:self.backView];
        self.backView.layer.cornerRadius = 5;
        self.backView.backgroundColor = [UIColor whiteColor];

        
        self.titleLabel = [UILabel new];
//        self.titleLabel.text = @"异地恋的你们，后来怎么样了？";
        self.titleLabel.font = CustomUIFont(13);
        self.titleLabel.textColor = FirstTextColor;
        [self.backView  addSubview:self.titleLabel];
        self.titleLabel.numberOfLines = 0;
        
        self.soundButton = [HRSoundButton new];
        [self.backView addSubview:self.soundButton];
        WeakSelf
        self.soundButton.playFunChatMedioBlock = ^(HRFunChatModel *funChatModel) {
            if (weakSelf.playFunChatMedioBlock){
                weakSelf.playFunChatMedioBlock(funChatModel);
            }
        };
        
        self.timeLabel = [UILabel new];
//        self.timeLabel.text = @"2分钟前";
        self.timeLabel.font = CustomUIFont(12);
        self.timeLabel.textColor = SecondTextColor;
        [self.backView  addSubview:self.timeLabel];
        
        self.statusLabel = [UILabel new];
//        self.statusLabel.text = @"结束发布";
        self.statusLabel.font = CustomUIFont(13);
        self.statusLabel.textColor = SecondTextColor;
        [self.backView  addSubview:self.statusLabel];
        
        
        
        self.deleteButotn = [UIButton buttonWithType:0];
        [self.deleteButotn setTitle:@"删除" forState:0];
        [self.deleteButotn setTitleColor:SecondTextColor forState:0];
        self.deleteButotn.titleLabel.font = CustomUIFont(13);
        [self.deleteButotn addTarget:self action:@selector(deleteButotnClick) forControlEvents:UIControlEventTouchUpInside];
        [self.backView addSubview:self.deleteButotn];
        self.deleteButotn.frame = CGRectMake(self.backView.width-60, self.statusLabel.top, 50, 20);
        
        
        
        self.ageinButton = [UIButton buttonWithType:0];
        [self.ageinButton setTitle:@"再发布" forState:0];
        [self.ageinButton setTitleColor:BlueColor forState:0];
        self.ageinButton.titleLabel.font = CustomUIFont(13);
        [self.ageinButton addTarget:self action:@selector(ageinButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [self.backView addSubview:self.ageinButton];
        
        DDLog(@"%f",self.ageinButton.bottom);
      
    }
    return self;
}

- (void)ageinButtonClick{
    if (self.sendBlock){
        self.sendBlock();
    }
}
- (void)deleteButotnClick{
    if (self.delelteCurrentTopicBlock){
        self.delelteCurrentTopicBlock();
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
